package user

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        url("/api/users") {
            queryParameters {
                parameter("nameOrEmail", "zhang")
            }
        }
        method("GET")
    }
    response {
        status(200)
        body("""
            [{
                "id":"1",
                "username":"zhang",
                "email":"zhang@qq.com",
                "mobilePhone":"12345678901",
                "createDate":"2018-08-08"
            },{
                "id":"2",
                "username":"li",
                "email":"li@qq.com",
                "mobilePhone":"12345678902",
                "createDate":"2018-08-08"
            }]""")
        bodyMatchers {
            jsonPath('$[*]', byType())
            jsonPath('$[*].id', byRegex(number()))
            jsonPath('$[*].username', byType())
            jsonPath('$[*].email', byRegex(email()))
            jsonPath('$[*].mobilePhone', byRegex(number()))
            jsonPath('$[*].createDate', byType())
        }
    }
}
